<?php
namespace app\livevideo\controller;
use app\AdminRest;
use longbingcore\wxcore\WxSetting;
use think\App;
use app\livevideo\model\LiveVideo as model;



class AdminLive extends AdminRest
{

    protected $model;


    public function __construct(App $app) {

        parent::__construct($app);

        $this->model = new model();

    }

    /**
     * User: chenniang
     * Date: 2019-12-18 14:30
     * @return void
     * descrption:员工发放记录
     */
    public function liveList(){


        $input = $this->_input;

        $dis[] = ['uniacid','=',$this->_uniacid];

        if(!empty($input['name'])){

            $dis[] = ['name','like','%'.$input['name'].'%'];
        }

        if(!empty($input['status'])){

            $dis[] = ['live_status','=',$input['status']];

        }

        if(!empty($input['date'])){

            $start_time = strtotime($input['date']);

            $end_time   = $start_time+86400;

            $dis[] = ['start_time','between',"$start_time,$end_time"];
        }

        $data = $this->model->liveList($dis,$input['limit']);

        return $this->success($data);
    }


    /**
     * @author chenniang
     * @DataTime: 2020-04-26 16:01
     * @功能说明:获取直播
     */
    public function getLive(){

        $WxSetting = new WxSetting($this->_uniacid);

        $access_token = $WxSetting->lbSingleGetAccessToken();

        $url = "https://api.weixin.qq.com/wxa/business/getliveinfo?access_token=$access_token";

        $send['start'] = 0;

        $send['limit'] = 999;

        $send = json_encode( $send, JSON_UNESCAPED_UNICODE );

        $res  = $WxSetting->curlPost($url,$send);

        $data = json_decode($res,true);

        if(!isset($data['room_info'])){

            $this->errorMsg('获取数据失败');
        }

        $res  = $this->model->initData($data['room_info'],$this->_uniacid);

        return $this->success($res);


    }












}
